import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;

/**
 * map的几种遍历方式
 */
public class MapDemo1 {
    public static void main(String[] args) {
        Map<String,Integer> maps = new HashMap<>();
        maps.put("哇哇",30);
        maps.put("iphone",50);
        maps.put("魅族",40);
        maps.put("一加",80);
        maps.put("锤子",9);

        //1.键找值
        Set<String> keys = maps.keySet();
        for (String key : keys) {
            int value = maps.get(key);
            System.out.println(key + value);
        }
        System.out.println("----------------------------------");

        //键值对,map没有固定的类型,通过内置方法可以转成set集合(将map对象封装为键值对类型)
        Set<Map.Entry<String, Integer>> entries = maps.entrySet();
        for (Map.Entry<String, Integer> entry : entries) {
            System.out.println(entry.getKey() + entry.getValue());
        }
        System.out.println("----------------------------------");

        //lambda表达式
        maps.forEach(new BiConsumer<String, Integer>() {
            @Override
            public void accept(String s, Integer integer) {
                System.out.println(s+integer);
            }
        });
        System.out.println("----------------------------------");
        //lambda简化为以下内容
        maps.forEach((s, integer) -> System.out.println(s+integer));
    }
}
